package com.zlzxm.shoesmarket.view.activity;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.ImageView;

import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.zlzxm.shoesmarket.R;
import com.zlzxm.shoesmarket.TestConstant;
import com.zlzxm.shoesmarket.util.ZViewHelp;
import com.zlzxm.shoesmarket.view.activity.manage.ActivityIndex;
import com.zlzxm.shoesmarket.view.adapter.ADRecruit;
import com.zlzxm.shoesmarket.view.adapter.entity.EntityRecruit;
import com.zlzxm.shoesmarket.view.widget.simpleead.SimpleHead;
import com.zlzxm.shoesmarket.viewmodel.VMRecruit;

import java.util.List;

/**
 * CREATE BY zlzxm ON 4/23/21
 * <br>
 *寻找代理/供应商
 */
public class ACRecruit extends BaseActivity implements View.OnClickListener {


    public static void start(Context context) {
        Intent starter = new Intent(context, ACRecruit.class);
        context.startActivity(starter);
    }

    private VMRecruit vmRecruit;

    private RecyclerView rvNote;

    private ADRecruit adRecruit = new ADRecruit();

    private ImageView ivFace;

    @Override
    protected void initView() {
        super.initView();
        setContentView(R.layout.ac_recruit);
        SimpleHead simpleHead = ZViewHelp.findById(this,R.id.head);
        simpleHead.setTitle("寻找代理/供应商");
        simpleHead.setOnItemclicklistener(this::finish);
        rvNote = ZViewHelp.findById(this,R.id.rvNote);
        rvNote.setLayoutManager(new LinearLayoutManager(this));
        rvNote.setAdapter(adRecruit);

        ZViewHelp.setOnClickListener(this,R.id.tvRelease,this);
        ivFace =   ZViewHelp.findById(this,R.id.ivFace);
    }

    @Override
    protected void initViewModule() {
        super.initViewModule();
        vmRecruit = new ViewModelProvider(this).get(VMRecruit.class);
        vmRecruit.getLiveRecruit().observe(this, new Observer<List<EntityRecruit>>() {
            @Override
            public void onChanged(List<EntityRecruit> entityRecruits) {
                adRecruit.setList(entityRecruits);
            }
        });
    }

    @Override
    protected void initData() {
        super.initData();

        Glide.with(this)
                .load(TestConstant.PIC_EIGHT)
                .centerCrop()
                .into(ivFace);

        vmRecruit.requestList();
    }

    @Override
    public void onClick(View view) {

        if(view.getId() ==R.id.tvRelease){

            startACReleaseACRecruit();
        }

    }


    private void startACReleaseACRecruit(){


        ActivityIndex.startACReleaseRecruit(this);


    }


}
